﻿// Copyright (c) 2013 Bryan C. O'Connell
// http://wsubi.codeplex.com/license
// Purpose: Reads and stores a Queue file into memory for use during runtime.

using System;
using System.IO;
using System.Collections.Generic;

namespace Wsubi
{
    class Queue
    {
        /// <param name="FullFilepath">Path and name of the queue file to be processed.</param>
        public Queue(string FullFilepath)
        { 
            if (File.Exists(FullFilepath)) 
            {
                _QueueFile = FullFilepath;

                ReadIntoMemory();
            }
            else
            {
                throw new FileNotFoundException("The specified Queue file doesn't seem to exist.");
            }
        }

        /// <summary>Reads the current Queue file and stores the values in memory.</summary>
        private void ReadIntoMemory()
        {
            _CommandQueue.Clear();

            using (StreamReader Reader = new StreamReader(_QueueFile))
            {
                string Line;
                while ((Line = Reader.ReadLine()) != null)
                {
                    _CommandQueue.Add(Line.Trim());
                }
            }

            if (_CommandQueue.Count == 0)
            {
                throw new FileLoadException("The Queue file specified does not contain any commands.");
            }
        }

        #region Properties / Variables

        // Current queue file.
        private string _QueueFile;

        // Stores the values from the current queue file.
        private List<string> _CommandQueue = new List<string>();
        public List<string> CommandQueue
        { get { return _CommandQueue; } }

        #endregion
    }
}
